<template>
  <div class="pass">
    <!-- 治愈管理 -->
    <el-breadcrumb separator="/">
      <el-breadcrumb-item :to="{ path: '/' }">首页</el-breadcrumb-item>
      <el-breadcrumb-item>治愈管理</el-breadcrumb-item>
    </el-breadcrumb>
    <!-- 卡片 -->
    <el-card>
        <div class="search">
        列表
        </div>
      <!-- 表格 -->
      <el-table :data="cureList">
        <el-table-column prop="base.id" label="baseID"></el-table-column>
        <el-table-column prop="base.uname" label="姓名"></el-table-column>
        <!-- 快速复制某行 alt+shift+剪头 -->
        <el-table-column prop="base.age" label="年龄"></el-table-column>
        <el-table-column
          prop="base.gender"
          label="性别"
        ></el-table-column>
        <el-table-column prop="base.address" label="住址"></el-table-column>
        <el-table-column prop="dischargeDate" label="出院日期"></el-table-column>
        <el-table-column prop="current" label="现状"></el-table-column>

      
        <!-- 只有当状态为待审核，也就是0时，才展示两个按钮 -->
        <!-- <el-table-column label="操作" width="200px">
          <template v-slot="scope">
            <div v-if="scope.row.status == 0">
              <el-button type="primary" @click="changeStatus(scope.row.id, 1)"
                >详情</el-button
              >
               <el-button color="red" type="danger" @click="deletePass(scope.row.id)"
                >删除</el-button
              >
            </div>
          </template>
        </el-table-column> -->
      </el-table>
      <el-pagination class="paging" background layout="prev, pager, next" :total="1000">
      </el-pagination>
    </el-card>
  </div>
</template>

<script>
// getAllPassAPi获取所有通行证 发请求
import { ElMessage } from "element-plus";
import {
  getAllPassAPi,
  deletePassApi,
  changePassStatusApi,
  getUserPassApi,
} from "../api/index.js";
import {
  getCureAPI,
} from "../api/index1.js";
export default {
  data() {
    return {
      passList: [],
      searchById:'',
      cureList:[]
    };
  },
  methods: {
    getCureList() {
      getCureAPI().then((res) => {
        console.log(res)
        this.cureList = res.data;
        // console.log(this.eventList)
      })
    },
    // 1.获取通行证列表的方法
    getPassList() {
      getAllPassAPi().then((res) => {
        // console.log(res)
        this.passList = res.data.data;
        // console.log(this.passList)
      });
    },
    // 2.根据id删除通行证
    deletePass(id) {
      deletePassApi(id).then((res) => {
        console.log(res);
        // 1.刷新数据
        this.getPassList();
        // 2.提示用户删除成功
        if (res.code == 20000) {
          ElMessage({
            message: "删除成功",
            type: "success",
          });
        }
      });
    },
    // 3.改变通行证状态
    changeStatus(id, status) {
      console.log(id + status);

      let obj = {
        id: id,
        status: status,
      };
      changePassStatusApi(obj).then((res) => {
        console.log(res);
        if (res.code == 20000) {
          this.getPassList();
          ElMessage({
            message: "更新成功",
            type: "success",
          });
        }
      });
    },
    // 4.搜索
    getPassListByUserId(){
        getUserPassApi(this.searchById).then(res=>{
            console.log(res)
            this.passList = res.data.pass
        })
    },
    // 5.重置
    reset(){
        this.searchById=''
        this.getPassList()
    }
  },
  created() {
    // this.getPassList();
    this.getCureList()
    
  },
};
</script>

<style lang="less" scoped>
.pass {
  .el-breadcrumb {
    margin-bottom: 30px;
  }
}
.search{
    width: 600px;
    display: flex;
    .el-input{
        margin-right: 30px;
    }
}
.paging {
    display: flex;
    justify-content: right;
  }
</style>